﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThuVien;
using System.Data;

namespace TranTekBE.Maintenance
{
    public partial class Maintenance: PageRequireLogin
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            func abc = new func();
            /*
            * Lấy danh sách top 5 yêu cầu mới nhất ( id, tiêu đề, nội dung, thời gian... )
            */
            DataSet listrequesttop5 = FunctionsUtils.Database2.ExecuteQuery("SELECT TOP 5 * FROM tbl_YeuCau ORDER BY ID DESC");
            if (listrequesttop5 != null)
            {
                foreach (DataRow Rows in listrequesttop5.Tables[0].Rows)
                {
                    top5request.Text += "<tr>";
                    top5request.Text += "<td>"+Rows[4].ToString()+"</td>";
                    top5request.Text += "<td>" + abc.getPhongBan(Rows[2].ToString()) + "</td>";
                    top5request.Text += "<td>" + abc.getCuaHang(Rows[10].ToString()) + "</td>";
                    top5request.Text += "<td>" + Rows[1].ToString() + "</td>";
                    top5request.Text += "<td>" + abc.getCapDo(Rows[6].ToString()) + "</td>";
                    top5request.Text += "<td><img src=\"img/" + Rows[7].ToString() + ".png\" title=\"" + abc.getTinhTrang(Rows[7].ToString()) + "\" alt=\"" + abc.getTinhTrang(Rows[7].ToString()) + "\" width=\"16\" height=\"16\">" + /*getTinhTrang(Rows[7].ToString()) +*/ "</td>";
                    top5request.Text += "<td class=\"textcenter\"><a href=\"Viewrequest.aspx?rid=" + Rows[0].ToString() + "\" class=\"btn btn-inverse\">Xem</a></td>";
                    top5request.Text += "</tr>";
                }
            }
            /*
            * Lấy danh sách top 5 yêu cầu quan trọng  ( id, tiêu đề, nội dung, thời gian... )
            */
            DataSet listrequesttop5importan = FunctionsUtils.Database2.ExecuteQuery("SELECT TOP 5 * FROM tbl_YeuCau WHERE IDTinhTrang < 3 ORDER BY IDCapDo DESC");
            if (listrequesttop5importan != null)
            {
                foreach (DataRow Rows in listrequesttop5importan.Tables[0].Rows)
                {
                    top5requestimportan.Text += "<tr>";
                    top5requestimportan.Text += "<td>" + Rows[4].ToString() + "</td>";
                    top5requestimportan.Text += "<td>" + abc.getPhongBan(Rows[2].ToString()) + "</td>";
                    top5requestimportan.Text += "<td>" + abc.getCuaHang(Rows[10].ToString()) + "</td>";
                    top5requestimportan.Text += "<td>" + Rows[1].ToString() + "</td>";
                    top5requestimportan.Text += "<td>" + abc.getCapDo(Rows[6].ToString()) + "</td>";
                    top5requestimportan.Text += "<td><img src=\"img/" + Rows[7].ToString() + ".png\" title=\"" + abc.getTinhTrang(Rows[7].ToString()) + "\" alt=\"" + abc.getTinhTrang(Rows[7].ToString()) + "\" width=\"16\" height=\"16\">" + /*getTinhTrang(Rows[7].ToString()) +*/ "</td>";
                    top5requestimportan.Text += "<td class=\"textcenter\"><a href=\"Viewrequest.aspx?rid=" + Rows[0].ToString() + "\" class=\"btn btn-inverse\">Xem</a></td>";
                    top5requestimportan.Text += "</tr>";
                }
            }
        }
        
        protected void addnew_Click(object sender, EventArgs e)
        {
            Response.Redirect("Add.aspx");
        }

        protected void seeall_Click(object sender, EventArgs e)
        {
            Response.Redirect("Allrequest.aspx");
        }
    }
}